<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","kdcust");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_custlist.php";
$FileTemplate  = "ais_transaction_custlist_formdn.html";

$PageSize      = 10 ;
$TableName     = "ais_piutang";
$HTMLGridList  = "CustomerGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}


//Initiate Database Table For Search;
//******* DATABASE FORM QUERY ***********
include("./sql_stored/ais_transaction_dnlist_sql.php");
$SQL = "SELECT ais_piutang.* FROM ais_piutang LEFT JOIN ais_dnlist ON ais_piutang.nobkt=ais_dnlist.nobkt WHERE ifnull(ais_dnlist.nobkt,'')='' AND ais_piutang.debtur='".GetParam("debtur","")."'";
$SQLCount = "SELECT count(*) FROM ais_piutang LEFT JOIN ais_dnlist ON ais_piutang.nobkt=ais_dnlist.nobkt WHERE ifnull(ais_dnlist.nobkt,'')='' AND ais_piutang.debtur='".GetParam("debtur","")."'";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName;	
	for ($x=1;$x<=$PageSize;$x++) {		
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("tblcustomer",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>